#include "testfactory.h"
#include "test.h"

namespace AllTing
{

namespace Test
{

TestFactory::~TestFactory()
{
}

TestFactory* TestFactory::Instance()
{
	static TestFactory theTestFactory;

	return &theTestFactory;
}

void TestFactory::Destroy()
{
	TestIterator itStart = theTests_.begin();
	TestIterator itEnd = theTests_.end();

	for(;itStart!=itEnd;++itStart)
	{
		if((*itStart))
		{
			delete *itStart;
			*itStart = Null;
		}
	}

	theTests_.clear();
}

Test* TestFactory::Create(::Func func, const Char* pszName, const Bool bSelect, const Bool bStopOnFailed)
{
	assert(func);
	assert(pszName);

	Test* pTest = new Test(func, pszName, bSelect, bStopOnFailed);
	
	theTests_.push_back(pTest);

	return pTest;
}

Test* TestFactory::Create(Testable* pTestee, Testable::Testee testee, const Char* pszName, const Bool bSelect, const Bool bStopOnFailed)
{
	assert(pTestee);
	assert(testee);
	assert(pszName);

	Test* pTest = new Test(pTestee, testee, pszName, bSelect, bStopOnFailed);
	
	theTests_.push_back(pTest);

	return pTest;
}

TestConstIterator TestFactory::BeginTest() const
{
	return theTests_.begin();
}

TestConstIterator TestFactory::EndTest() const
{
	return theTests_.end();
}


}

}	// namespace AllTing